<?php


namespace Modules\Auth\Services;

use Illuminate\Support\Facades\Hash;
use Modules\Auth\API\APIHelper;
use Modules\Auth\Entities\User;
use Modules\Common\Services\BaseService;

class UserService extends BaseService
{
    private $helper;
    private $options;
    public function __construct(APIHelper $helper)
    {
        $this->helper = $helper;
        $this->options = $this->helper->getClientConfig('user');
    }

    public function register(array $data) : User{
        $password= $data['password1'];
        unset($data['password1']);
       $res = User::create($data);

     //   $this->helper->Login(array_merge(['name'=>$data['name'],'password'=> $password],$this->options));
       return $res;
    }
    public function login(array $data){
        $user = new User();
        $user=$user->findForPassport($data['name']);
        if ( $user ) {
            if (Hash::check($data['password'], $user->password)) {

              return  $this->helper->Login($data['name'],$data['password'],$this->options);
            }
        }
        return false;

    }
}
